from datetime import datetime
from sqlmodel import Field, SQLModel, Index
from typing import Optional

class XmUser(SQLModel, table=True):
    """XM用户表数据库模型"""
    __tablename__ = "t_xm_user"  # 对应数据库表名

    # 索引定义（优化查询性能）
    __table_args__ = (
        Index("idx_internalUid", "internalUid", unique=True, info="用户内部UID唯一索引"),
    )

    id: Optional[int] = Field(default=None, primary_key=True, index=True, description="主键，自增ID")
    alipayAccount: str = Field(default="", max_length=64, description="支付宝账号")
    alipayName: str = Field(default="", max_length=64, description="支付宝姓名")
    bankCardNumber: str = Field(default="", max_length=64, description="银行卡号")
    bankName: str = Field(default="", max_length=64, description="银行名称")
    certificationStatus: int = Field(default=0, description="实名认证状态")
    certificationTime: datetime = Field(default_factory=datetime.now, description="实名认证时间")
    city: str = Field(default="", max_length=128, description="城市")
    createTime: datetime = Field(default_factory=datetime.now, description="创建时间")
    email: str = Field(default="", max_length=128, description="邮箱")
    growthScore: int = Field(default=0, description="赚力值")
    hasJintanToken: int = Field(default=0, description="是否有鲸探令牌, 0: 无, 1: 有")
    headImg: str = Field(default="", max_length=256, description="头像URL")
    highQualityUserMedalImg: str = Field(default="", max_length=256, description="高质量用户勋章图片URL")
    idCard: str = Field(default="", max_length=64, description="身份证号")
    isCertification: int = Field(default=0, description="是否实名认证, 0: 否, 1: 是")
    isHfPayOpen: int = Field(default=0, description="是否开启HF支付, 0: 否, 1: 是")
    isHidePhone: int = Field(default=0, description="是否隐藏手机号, 0: 否, 1: 是")
    isHighQualityUser: int = Field(default=0, description="是否高质量用户, 0: 否, 1: 是")
    isInWithdrawBlacklist: int = Field(default=0, description="是否在提现黑名单, 0: 否, 1: 是")
    isOpenTransportAccount: int = Field(default=0, description="是否开启运输账号, 0: 否, 1: 是")
    jtPhone: str = Field(default="", max_length=32, description="鲸探手机号")
    memberLevel: int = Field(default=0, description="会员等级")
    memberLevelImg: str = Field(default="", max_length=256, description="会员等级图片URL")
    memberLevelName: str = Field(default="", max_length=64, description="会员等级名称")
    nickName: str = Field(default="", max_length=64, description="昵称")
    openBank: str = Field(default="", max_length=64, description="开户行")
    openid: str = Field(default="", max_length=128, description="openid")
    phone: str = Field(default="", max_length=32, description="手机号")
    province: str = Field(default="", max_length=64, description="省份")
    realName: str = Field(default="", max_length=64, description="真实姓名")
    rentHireEarnestMagnification: int = Field(default=0, description="出租雇佣定金 magnification")
    sellEarnestMoneyStatus: int = Field(default=0, description="出售定金状态")
    sex: int = Field(default=0, description="性别")
    token: str = Field(default="", max_length=256, description="用户Token")
    transportOpenAccountStatus: str = Field(default="", max_length=32, description="运输账号状态")
    uid: int = Field(default=0, description="Xm用户UID")
    userOrderType: int = Field(default=0, description="用户订单类型")
    internalUid: int = Field(default=0, description="内部用户UID")
